package top.fengleifeng.question;

/**
 * @program: leetcode-test
 * @description:
 * @author: fengleifeng
 * @create: 2020-10-19 14:14
 **/
public class Num844比较含退格的字符串 {
    class Solution {
        public boolean backspaceCompare(String S, String T) {
            String s_now = "", t_now = "";
            s_now = check(S);
            t_now = check(T);
            return s_now.equals(t_now);
        }

        private String check(String s) {
            StringBuilder sb = new StringBuilder("");
            char[] one = s.toCharArray();
            for (int i = 0; i < one.length; i++) {
                if (one[i] != '#') {
                    sb = sb.append(one[i]);
                } else {
                    if(sb.length()>0){
                        sb = sb.deleteCharAt(sb.length() - 1);
                    }
                }
            }
            return sb.toString();
        }
    }

    public static void main(String[] args) {

    }
}
